{% extends "base.html" %}
{% load i18n %}

{% block pageContent %}
	<div id="searchResults">
		<p id="numSearchResults"> 
			{% if searchResultsPage %}
				{% blocktrans count totalResults as totalResults %}
					{{ totalResults }} search result found.
				{% plural %}
					{{ totalResults }} search results found.
				{% endblocktrans %}
				{% blocktrans %}
				Showing {{ startIndex }} to {{ endIndex }}:
				{% endblocktrans %}
			{% endif %}
		</p>
		{% for result in searchResults %}
		<div class="searchResult" id="result-{{ result.videoID }}">
			<img src="{{ result.thumbURL }}" width="120" height="90"/>
			<div class="videoStats">
				{% trans "From" %}: <a href="http://tw.youtube.com/user/{{ result.author }}">{{ result.author }}</a><br/>
				{% trans "Duration" %}: {{ result.duration }}<br/>
				{% trans "Views" %}: {{ result.views }}<br/>
				{% trans "Rating" %}: {{ result.rating }}
			</div>
			<div class="videoInfo">
				<h3><span class="highlightLink" id="highlight-{{ result.videoID }}"><img src="/static/images/ajax-loader.gif" width="12" height="12"/></span>{{ result.title|truncatewords:"10" }}</h3>
				<p>
					{{ result.description|truncatewords:"35" }}
				</p>
			</div>
		</div>
		{% endfor %}
		<div class="paginator" align="center">
			<p>
{% include "include/digg_paginator.html" %}
			</p>
		</div>
	</div>

	<script type="text/javascript">
<!--
function setEmbeddableToResult(videoID, embeddable) {
	var el = $('#result-'+videoID);
	if (embeddable) {
		el.children('.videoInfo').children('h3').wrapInner('<a href="http://{{ siteHostname }}/loop/youtube/'+videoID+'"></a>')
		el.children('img').wrap('<a href="http://{{ siteHostname }}/loop/youtube/'+videoID+'"></a>');
		renderHighlightLink(videoID, false, true);
	} else {
		el.children('.videoInfo').children('h3').children('span.highlightLink').remove();
		el.children('.videoInfo').children('h3').after('<p>(<b>{% trans "Not Loopable" %}</b> - <a href="http://www.youtube.com/watch?v='+videoID+'" target="_blank">{% trans "Watch on YouTube" %}</a>)</p>')
	}
}

$(function(){
	$('div.searchResult').each(function(){
		var videoID = $(this).attr('id').substr(7);
		$.getJSON('http://{{ siteHostname }}/channel/fetch?videoID='+videoID, function(data) {
			if (data.videoID) {
				setEmbeddableToResult(videoID, true);
			} else {
				setEmbeddableToResult(videoID, false);
			}
		});				
	});
});
-->
	</script>
{% endblock pageContent %}